import React, { PureComponent } from 'react';
import { connect } from 'dva';
import GridContent from '@/components/PageHeaderWrapper/GridContent';
import { Card, Row, Col, message, Modal, Divider, Select, Form, Button, Input, Popconfirm, Empty, Tag } from 'antd';

const Option = Select.Option;

@connect(({ user, competition }) => ({
  teacherList: user.teacherList,
  gradeTeacher: competition.gradeTeacher,
}))
@Form.create()
class ScoreTeacherSetting extends PureComponent {
  state = {

  }

  componentDidMount() {
    const { dispatch } = this.props;

    dispatch({
      type: 'user/getTeacherList',
    })
    dispatch({
      type: 'competition/getGradeTeacher',
    })

  }



  handleChange = (value) => {
    console.log(`selected ${value}`);
  }

  handleClick = () => {
    const {
      form: { validateFieldsAndScroll },
      dispatch,
    } = this.props;
    validateFieldsAndScroll((error, values) => {
      if (!error) {
        console.log(values)
        dispatch({
          type: 'competition/setGradeTeacher',
          payload: values,
          callback:(res)=>{
            message.success("设置成功")
          }
        })
      }
    });
  }

  render() {
    const { teacherList, form: { getFieldDecorator }, gradeTeacher } = this.props;
    console.log(teacherList)
    console.log(gradeTeacher)

    const children = [];
    teacherList.map((item, index) => (
      children.push(<Option key={item.id}>{item.username}</Option>)
    ))


    return (
      <GridContent>
        <Card>
          <Row>
            <Col lg={8}>
              <Form>
                <Form.Item label="设置参与该竞赛评分的人员">
                  {getFieldDecorator('gradeTeachers', {
                    rules: [{ required: true }],
                    initialValue: gradeTeacher
                  })(<Select
                    mode="multiple"
                    style={{ width: '100%' }}
                    placeholder="Please select"
                    onChange={this.handleChange}
                  >
                    {children}
                  </Select>)}
                </Form.Item>
              </Form>
              <Button type="primary" onClick={this.handleClick}>
                设置
              </Button>
            </Col>
          </Row>
        </Card>
      </GridContent>
    )
  }
}
export default ScoreTeacherSetting